﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WorkflowWizart.Lib.Utility.Costants;
using System.Collections;
using System.Text.RegularExpressions;
using System.Reflection;

namespace WorkflowWizart.Lib.Utility
{
    public class CompareHelper
    {
        public static bool IsNullOrDefault(object data)
        {

            if (data == null || data == DBNull.Value)
            {
                return true;
            }

            if (data.GetType() == typeof(DateTime))
            {
                if (ConvertHelper.ToDateTime(data) <= TypeValues.DateTimeDefaultValue)
                {
                    return true;
                }
            }

            if (data.GetType() == typeof(string))
            {
                if (ConvertHelper.ToString(data) == string.Empty || ConvertHelper.ToString(data).Trim() == string.Empty)
                {
                    return true;
                }
            }

            if (data.GetType() == typeof(Guid) || IsGuid(data))
            {
                if (ConvertHelper.ToGuid(data) == Guid.Empty)
                {
                    return true;
                }
            }
          
            return false;
        }

        public static bool IsGuid(object data)
        {
            Guid convertedGuidData = Guid.Empty;
            return ConvertHelper.TryParseToGuid(data, out convertedGuidData);
        }

        public static bool IsInt(object data)
        {
            int controllerValue = 0;
            if (int.TryParse(ConvertHelper.ToString(data), out controllerValue))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static bool IsDecimal(object data)
        {
            decimal controllerValue = 0;
            if (decimal.TryParse(ConvertHelper.ToString(data), out controllerValue))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static bool IsDateTime(object data)
        {
            DateTime controllerValue = DateTime.MinValue;
            if (DateTime.TryParse(ConvertHelper.ToString(data), out controllerValue))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static bool IsBool(object data)
        {
            bool controllerValue = false;
            if (bool.TryParse(ConvertHelper.ToString(data), out controllerValue))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static bool IsLong(object data)
        {
            long controllerValue = -1;
            if (long.TryParse(ConvertHelper.ToString(data), out controllerValue))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static bool IsTime(object data)
        {
            TimeSpan controllerValue = TimeSpan.MinValue;
            if (TimeSpan.TryParse(ConvertHelper.ToString(data), out controllerValue))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static bool isEmail(object data)
        {
            string inputEmail = ConvertHelper.ToString(data);

            if (string.IsNullOrEmpty(inputEmail))
                return false;

            string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                  @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                  @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            Regex re = new Regex(strRegex);
            if (re.IsMatch(inputEmail))
                return (true);
            else
                return (false);
        }


        public static bool IsGuidsCompares(object data, object toData)
        {
           

            string dataString = ConvertHelper.ToString(data);
            string toDataString = ConvertHelper.ToString(toData);
            if (!string.IsNullOrEmpty(dataString) && !string.IsNullOrEmpty(toDataString))
            {
                if (dataString.Replace("{", "").Replace("}", "").ToLower() == toDataString.Replace("{", "").Replace("}", "").ToLower())
                {
                    return true;
                }
            }
            return false;
        } 
    }

}
